from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from config.config import HOST

class AddTaskPage(BasePage):
    # 添加应收款页面url
    url='http://{}/crm/index.php?m=task&a=add'.format(HOST)

    # 任务主题定位
    subject_locator = (By.NAME, 'subject')
    # 任务负责人定位
    task_holders_locator = (By.ID, 'owner_name')
    # 选择任务负责人定位
    select_task_holder_locator = (By.XPATH, '//*[@id="ta1"]/span[1]/input')
    # 确定任务负责人定位
    task_ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')
    # 定位保存按钮
    task_save_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')
    # 添加任务成功的提示语定位
    add_task_success_locator=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    # 返回按钮
    back_btn_locator=(By.CSS_SELECTOR,"body > div.container > div.row-fluid > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(3)")
    '''输入任务主题'''
    def input_task_subject(self,subject):
        self.driver.find_element(*self.subject_locator).send_keys(subject)
    '''点击任务负责人'''
    def click_task_holder(self):
        self.driver.find_element(*self.task_holders_locator).click()
    '''选择任务负责人'''
    def select_task_holder(self):
        self.driver.find_element(*self.select_task_holder_locator).click()
    '''点击任务负责人选择框的ok'''
    def click_task_ok(self):
        self.driver.find_element(*self.task_ok_locator).click()
    ''''点击添加任务的确定按钮'''
    def click_task_save(self):
        self.driver.find_element(*self.task_save_locator).click()

    # 获取添加任务成功的提示语
    def add_task_success_tips(self):
        tips=self.driver.find_element(*self.add_task_success_locator).text
        return tips

    def click_back_btn(self):
        # 点击返回
        self.driver.find_element(*self.back_btn_locator).click()













    # 获取任务页面的url地址
    def get_task_url(self):
        return self.current_url()